﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BTicino.BtCommLib.Mappers;
using BTicino.BtCommLib.Attributes;
using BTicino.BtCommLib.Exceptions;

namespace BTicino.BtCommLib.Test
{
    /// <summary>
    /// This class is used to translate from high level language to BTicino "DIMENSION"
    /// code parameter and viceversa.
    /// </summary>
    public class MyDimensionMapper : IMapper
    {
        private Dictionary<string, string> dictToLowLevel_Temp = new Dictionary<string, string>();
        private Dictionary<string, string> dictToHighLevel_Temp = new Dictionary<string, string>();

        public MyDimensionMapper()
        {
            dictToLowLevel_Temp.Add("MEASURED_TEMPERATURE", "0");
            dictToLowLevel_Temp.Add("SENSOR_STATE", "12");
            dictToLowLevel_Temp.Add("LOCAL_CONFIG", "13");
            dictToLowLevel_Temp.Add("SETPOINT_TEMPERATURE", "14");
    

            dictToHighLevel_Temp.Add("0", "MEASURED_TEMPERATURE");
            dictToHighLevel_Temp.Add("12", "SENSOR_STATE");
            dictToHighLevel_Temp.Add("13", "LOCAL_CONFIG");
            dictToHighLevel_Temp.Add("14", "SETPOINT_TEMPERATURE");
       
        }

        /// <summary>
        /// Traslator from high level message to low level message. For specific messages it need the
        /// HighLevelCtxAttr object to discriminate correct value 
        /// </summary>
        /// <param name="key">Key string, it allows to find low level message associate to specifi high level message</param>
        /// <param name="ctxAttr">Object contains other frame information (eg. WHO, WHAT, etc...)</param>
        /// <returns>Low level message</returns>
        public string GetValueToLowLevel(string key, HighLevelCtxAttr ctxAttr)
        {
            if (ctxAttr.GetCtxAttr(BTAttributeName.Who).Equals(WhoValues.Termo.GetHashCode().GetHashCode().ToString()))
                if (dictToLowLevel_Temp.ContainsKey(key))
                    return dictToLowLevel_Temp[key];
            throw new LibException();
            
        }

        /// <summary>
        /// Traslator from low level message to high level message. For specific messages it need the
        /// LowLevelCtxAttr object to discriminate correct value 
        /// </summary>
        /// <param name="key">Key string, it allows to find high level message associate to specifi low level message</param>
        /// <param name="ctxAttr">Object contains other frame information (eg. WHO, WHAT, etc...)</param>
        /// <returns>High level message</returns>
        public string GetValueToHighLevel(string key, LowLevelCtxAttr ctxAttr)
        {
            if (ctxAttr.GetCtxAttr(BTAttributeName.Who).Equals(WhoValues.Termo.GetHashCode().ToString()))
                if (dictToHighLevel_Temp.ContainsKey(key))
                    return dictToHighLevel_Temp[key];
            throw new LibException();
        }
    }
}